﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data.OleDb;
using System.Configuration;

namespace WebService1
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class Service1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string Chance(string username)
        {
            Random r = new Random();
            int random_broj;
            random_broj = r.Next(1, 24);

            //citame random poraka od bazata
            string conString = ConfigurationManager.ConnectionStrings["Database"].ConnectionString;
            OleDbConnection conn = new OleDbConnection(conString);
            conn.Open();

            string select_poraka = "Select poraka from Table1 where ID LIKE '" + random_broj.ToString() + "' ";
            OleDbCommand cmd = new OleDbCommand(select_poraka, conn);

            OleDbDataReader prv = cmd.ExecuteReader();
            prv.Read();

            String poraka = prv.GetString(0);
            prv.Close();

            string select_pari = "Select pari from Table1 where ID LIKE '" + random_broj.ToString() + "' ";
            OleDbCommand cmd1 = new OleDbCommand(select_pari, conn);

            OleDbDataReader vtor = cmd1.ExecuteReader();
            vtor.Read();

            Int32 pari = vtor.GetInt32(0);
            vtor.Close();

            banka bb=new banka();
            banka.depositMoney(username, pari);
            
            conn.Close();
            
            return poraka;
        }
    }
}